package com.jk.controller;

import com.jk.entity.*;
import com.jk.service.ProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("product")
@CrossOrigin(origins = "*")
public class ProductController {

    @Autowired
    private ProductService productService;

    /*1* @Return *
    2* @Author: lxb
    3* @Description:
    4* @Date: 2022/11/2 15:49
    5 * @param null 
    6: 查询类型列表
    **/
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("getTypeList")
    public Map getTypeList(ProductTypeEntity productTypeEntity) {
        return productService.getTypeList(productTypeEntity);
    }

    //删除类型
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("deleteType")
    public Map deleteType(Integer id) {
        return productService.deleteType(id);
    }

    //新增产品类型
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("addType")
    public Map addType(ProductTypeEntity type) {
        return productService.addType(type);
    }

    //查看类型信息
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("getTypeById")
    public Map getTypeById(Integer id) {
        return productService.getTypeById(id);
    }

    //编辑产品类型信息
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("updateProType")
    public Map updateProType(ProductTypeEntity type) {
        return productService.updateProType(type);
    }

    //查看产品信息
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("getProList")
    public Map getProList(ProductEntity product) {
        return productService.getProList(product);
    }

    //新增产品
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("addPro")
    public Map addPro(ProductEntity product) {
        return productService.addPro(product);
    }

    //删除产品
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("deletePro")
    public Map deletePro(Integer id) {
        return productService.deletePro(id);
    }

    //回显产品信息
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("getProById")
    public Map getTProById(Integer id) {
        return productService.getTProById(id);
    }

    //修改产品信息
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("updatePro")
    public Map updatePro(ProductEntity product) {
        return productService.updatePro(product);
    }

    //进货
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("add")
    public Map add(PurRecord purRecord) {
        return productService.add(purRecord);
    }

    //查看进货记录
    @RequiresPermissions("ROLE_ADMIN")
    @RequestMapping("getNote")
    public Map getNote(PurRecord purRecord) {
        return productService.getNote(purRecord);
    }


    //查看前3个产品
    @RequestMapping("getcount")
    public List<ProductEntity> getcount(ProductEntity product) {
        return productService.getcount(product);
    }

    //全部产品
    @RequestMapping("getallget")
    public List<ProductEntity> getallget(ProductEntity product) {
        return productService.getallget(product);
    }

    //根据id查看数据（购买商品）
    @RequestMapping("getByid")
    public List<ProductEntity> getByid(ProductEntity product) {
        return productService.getByid(product);
    }

    //加入购物车
    @RequestMapping("getredis")
    public void getredis(Integer id, Integer buycount, Integer userId) {
        productService.getredis(id, buycount, userId);
    }

    //取redis
    @RequestMapping("getquredis")
    public List<ProductEntity> getquredis(Integer userId) {
        return productService.getquredis(userId);
    }

    //删除redis
    @RequestMapping("deletee")
    public void deletee(Integer id, Integer userId) {
        productService.deletee(id, userId);
    }

    //    App轮播图
    @RequestMapping("pruduceFindAll")
    public List<ProductEntity> pruduceFindAll(ProductEntity productEntity) {
        return productService.pruduceFindAll(productEntity);
    }

    //    查具体商品
    @RequestMapping("pruduceid")
    public ProductEntity pruduceid(Integer id) {
        return productService.pruduceid(id);
    }


    //产看排行榜
    @RequestMapping("getPaihang")
    public List<ProductEntity> getPaihang(ProductEntity productEntity) {
        return productService.getPaihang(productEntity);
    }

    @RequestMapping("getKillById")
    public Map getKillById(Integer id){
        return  productService.getKillById(id);
    }

    @RequestMapping("updateKill")
    public void updateKill(SecondKillEntity secondKill){
        productService.updateKill(secondKill);
    }

    //存入购买订单
    @RequestMapping("modo")
    public void modo(Integer id,Integer userId,Integer buycount){
        productService.modo(id,userId,buycount);
    }

}
